using ThirdLife.UI.WinForms.Controls;

namespace ThirdLife.UI.WinForms.Modules
{
  public class AddressBarUIModule : IUIModule
  {
    private TLAddressBar _addressbar;
    private IUIModuleServices _moduleServices;

    #region IUIModule Members

    public IUIModuleServices ModuleServices
    {
      get { return _moduleServices; }
      set { _moduleServices = value; }
    }

    public string Name
    {
      get { return "ThirdLife_AddressBar"; }
    }

    public void Setup()
    {
      _addressbar = new TLAddressBar(this);
      ModuleServices.Startup.ApplicationStarted += Startup_ApplicationStarted;
      ModuleServices.Metaverse.ConnectedToGrid += new GenericEventHandler(Metaverse_ConnectedToGrid);
    }

    
    void Metaverse_ConnectedToGrid()
    {
      //when we are connected to a grid, show an x so we can disconnect
      _addressbar.ShowMetaverseDisconnectButton();
    }


    #endregion

    private void Startup_ApplicationStarted()
    {
      ModuleServices.Registration.AddToMainScreen(_addressbar, new DockLocation(_addressbar.Height, 1, true));
    }

    public void DisconnectFromMetaverse()
    {
      ModuleServices.Metaverse.RequestDisconnectionFromMetaverse();
      _addressbar.HideMetaverseDisconnectButton();
    }

    public void ConnectToGridUsingDefaultUserNamePass(string url)
    {
      ModuleServices.Metaverse.ConnectToGridWithInfo(ModuleServices.Metaverse.DefaultName,ModuleServices.Metaverse.DefaultPassword,url);
    }

    public void BringUpGridList()
    {
      ModuleServices.Navigation.BringUpGridList();
    }

    public void ConnectToHomeGrid()
    {
      ModuleServices.Metaverse.ConnectToGridWithInfo(ModuleServices.Metaverse.DefaultName, ModuleServices.Metaverse.DefaultPassword, ModuleServices.Metaverse.DefaultURL);
    }
  }
}